#include "thread_hdr.h"
unsigned int first_time_ticks = 0, second_time_ticks = 0 ,time_interval = 0;

void add_ready_thread(thread* ready_thread)
{
    first_ready_queue.push_back(ready_thread);
    ready_thread->max_clock_times = first_time_ticks;
	// 相应的代码实现
}

void schedule_2_first_ready_queue()
{
    current_thread = first_ready_queue.front();
    first_ready_queue.pop_front();
}

void schedule_2_second_ready_queue()
{
    current_thread = second_ready_queue.front();
    second_ready_queue.pop_front();
}

void normal_shedule()
{
    if (first_ready_queue.size() != 0) schedule_2_first_ready_queue();
    else if(second_ready_queue.size() != 0) schedule_2_second_ready_queue();
    else current_thread = &idle_thread;
    current_thread->clock_times = 0;
}


void current_thread_finished()
{
    current_thread = NULL;
    normal_shedule();
    // 相应的代码实现
}

void current_thread_blocked()
{
    current_thread->clock_times = 0;
    blocked_queue.push_back(current_thread);
    current_thread = NULL;
    normal_shedule();
    // 相应的代码实现
}

void notify()
{
    if (blocked_queue.empty()) return;
    add_ready_thread(blocked_queue.front());
    blocked_queue.pop_front();
    // 相应的代码实现
}

void notify_all()
{
    while (!blocked_queue.empty())
    {
        notify();
    }
    
    // 相应的代码实现
}

void on_clock()
{
    current_thread->clock_times += time_interval;
    if (current_thread != &idle_thread && current_thread != NULL)//当有进程时
	{
        if (current_thread->clock_times >= current_thread->max_clock_times ||(current_thread->max_clock_times == second_time_ticks && first_ready_queue.size() != 0))
        {
            current_thread->clock_times = 0;
            current_thread->max_clock_times = second_time_ticks;//二级时间片
            second_ready_queue.push_back(current_thread);
            normal_shedule();
        }
    }
    else normal_shedule();
    // 相应的代码实现
}


void set_first_time_ticks(unsigned int ticks)
{
    first_time_ticks = ticks;
    // 相应的代码实现
}

void set_second_time_ticks(unsigned int ticks)
{
    second_time_ticks = ticks;
    // 相应的代码实现
}

void set_time_interval(unsigned int interval)
{
    time_interval = interval;
    // 相应的代码实现
}